package com.shenmazong.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shenmazong.entity.TbArticleType;
import com.shenmazong.mapper.TbArticleTypeMapper;
import com.shenmazong.service.TbArticleTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.ListParamVo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 技术文章类型表   ——> John 服务实现类
 * </p>
 *
 * @author 还怕大雨吗
 * @since 2021-09-18
 */
@Service
public class TbArticleTypeServiceImpl extends ServiceImpl<TbArticleTypeMapper, TbArticleType> implements TbArticleTypeService {

    @Resource
    private TbArticleTypeMapper tbArticleTypeMapper;


    /***
     * @description 查询全部分类
     * @params [listParamVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/18 13:13
     */
    @Override
    @Cacheable(value = "selectArticleType")
    public ResultResponse selectArticleType(ListParamVo listParamVo) {
        Page<TbArticleType> tbArticleTypePage = tbArticleTypeMapper.selectPage(
                new Page<TbArticleType>(listParamVo.getCurrent(), listParamVo.getSize()),null);

        return ResultResponse.SUCCESS(tbArticleTypePage);
    }

    /***
     * @description 删除分类信息
     * @params [listParamVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/18 13:16
     */
    @Override
    @CacheEvict(value = "selectArticleType",allEntries = true)
    public ResultResponse deleteArticleType(Long typeId) {
//        if ( "管理员" )
        tbArticleTypeMapper.deleteById(typeId);
        return ResultResponse.SUCCESS();
    }

    /***
     * @description 修改分类信息
     * @params [listParamVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/18 13:16
     */
    @Override
    @CacheEvict(value = "selectArticleType",allEntries = true)
    public ResultResponse updateArticleType(TbArticleType listParamVo) {
        tbArticleTypeMapper.updateById(listParamVo);
        return ResultResponse.SUCCESS();
    }

    /***
     * @description 新增一个分类
     * @params [listParamVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author -还怕大雨吗
     * @date 2021/9/18 13:16
     */
    @Override
    @CacheEvict(value = "selectArticleType",allEntries = true)
    public ResultResponse insertArticleType(TbArticleType listParamVo) {
        tbArticleTypeMapper.insert(listParamVo);
        return ResultResponse.SUCCESS();
    }
}
